package br.com.dj.persistencia;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import br.com.dj.entidade.GenericEntity;
import br.com.dj.enumerador.Status;

public abstract class SuporteDao<T extends GenericEntity> extends
		HibernateDaoSupport {

	@Autowired
	public void anyMethodName(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}

	public abstract Class<T> getClasse();

	public T incluir(T entidade) {
		getHibernateTemplate().save(entidade);
		return entidade;

	}

	public void alterar(T entidade) {
		getHibernateTemplate().update(entidade);
		getHibernateTemplate().flush();
	}

	@SuppressWarnings("unchecked")
	public List<T> coletarTodos() {
		Criteria criteria = getSession().createCriteria(getClasse()).add(
				Restrictions.ne("status", Status.REMOVIDO));
		return criteria.list();
	}
}
